home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 January / enter-2004-01.iso / files / maxima-5.9.0.exe / {app} / share / maxima / 5.9.0 / src / ldisp.lisp < prev    next >
Encoding:
Text File  |  2003-02-09  |  4.6 KB  |  154 lines

  1. ;;; -*-  Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;;     The data in this file contains enhancments.                    ;;;;;
  4. ;;;                                                                    ;;;;;
  5. ;;;  Copyright (c) 1984,1987 by William Schelter,University of Texas   ;;;;;
  6. ;;;     All rights reserved                                            ;;;;;
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8. ;;; Auxiliary DISPLA package for doing 1-D display
  9. ;;;
  10. ;;; (c) 1979 Massachusetts Institute of Technology
  11. ;;;
  12. ;;; See KMP for details
  13.  
  14. (in-package "MAXIMA")
  15. (declare-top (*EXPR MSTRING STRIPDOLLAR)
  16.      (SPECIAL LINEAR-DISPLAY-BREAK-TABLE FORTRANP))
  17.  
  18. #+Maclisp
  19. (EVAL-WHEN (EVAL COMPILE)
  20.        (SSTATUS MACRO /# '+INTERNAL-/#-MACRO SPLICING))
  21.  
  22. ;;; (LINEAR-DISPLA <thing-to-display>)
  23. ;;;
  24. ;;; Display text linearly. This function should be usable in any case
  25. ;;;  DISPLA is usable and will attempt to do something reasonable with
  26. ;;;  its input.
  27.  
  28.  
  29. ;;;The old linear-displa used charpos, not available in common lisp.
  30. ;;;It also did a much worse job on the display, breaking inside things
  31. ;;;like x^2.  --wfs
  32.  
  33. #+cl
  34. (DEFUN LINEAR-DISPLA (X )
  35.        (declare (special chrps))
  36.        (fresh-line *standard-output*)
  37.        (COND ((NOT (ATOM X))
  38.           (COND ((EQ (CAAR X) 'MLABLE)
  39.              (setq chrps 0)
  40.              (COND ((CADR X)
  41.                 (princ "(")
  42.                 (setq chrps
  43.                   (+  3 (length (mgrind (cadr x) nil))))
  44.                 (princ ") ")))
  45.              (MPRINT (MSIZE (caddr x) NIL NIL 'MPAREN 'MPAREN)
  46.                  *standard-output*))
  47.             ((EQ (CAAR X) 'MTEXT)
  48.              (DO ((X (CDR X) (CDR X))
  49.               (FORTRANP))            ; Atoms in MTEXT
  50.              ((NULL X))            ;  should omit ?'s
  51.              (SETQ FORTRANP (ATOM (CAR X)))
  52.              ;(LINEAR-DISPLA1 (CAR X) 0.)
  53.              (mgrind (car x) *standard-output*)
  54.              ;(tyo #\space )
  55.              ))
  56.             (T
  57.              (mgrind x *standard-output*))))
  58.          (T
  59.           (mgrind X *standard-output*)))
  60.         (TERPRI))
  61.  
  62.  
  63.  
  64. ;;; (LINEAR-DISPLA <thing-to-display>)
  65. ;;;
  66. ;;; Display text linearly. This function should be usable in any case
  67. ;;;  DISPLA is usable and will attempt to do something reasonable with
  68. ;;;  its input.
  69. #-cl
  70. (DEFUN LINEAR-DISPLA (X)
  71.        (TERPRI)
  72.        (COND ((NOT (ATOM X))
  73.           (COND ((EQ (CAAR X) 'MLABLE)
  74.              (COND ((CADR X)
  75.                 (PRIN1 (LIST (STRIPDOLLAR (CADR X))))
  76.                 (TYO #\space)))
  77.              (LINEAR-DISPLA1 (CADDR X) (CHARPOS T)))
  78.             ((EQ (CAAR X) 'MTEXT)
  79.              (DO ((X (CDR X) (CDR X))
  80.               (FORTRANP))            ; Atoms in MTEXT
  81.              ((NULL X))            ;  should omit ?'s
  82.              (SETQ FORTRANP (ATOM (CAR X)))
  83.              (LINEAR-DISPLA1 (CAR X) 0.)
  84.              ;(TYO #\space)
  85.              ))
  86.             (T
  87.              (LINEAR-DISPLA1 X 0.))))
  88.          (T
  89.           (LINEAR-DISPLA1 X 0.)))
  90.         (TERPRI))
  91.  
  92.  
  93. ;;********** old linear-displa *************
  94. ;;; LINEAR-DISPLAY-BREAK-TABLE
  95. ;;;  Table entries have the form (<char> . <illegal-predecessors>)
  96. ;;;
  97. ;;;  The linear display thing will feel free to break BEFORE any
  98. ;;;  of these <char>'s unless they are preceded by one of the
  99. ;;;  <illegal-predecessor> characters.
  100.  
  101. #-cl
  102. (SETQ LINEAR-DISPLAY-BREAK-TABLE
  103.       '((#\= #\: #\=)
  104.     (#. left-parentheses-char #. left-parentheses-char #\[)
  105.     (#. right-parentheses-char #. right-parentheses-char #\])
  106.     (#\[ #. left-parentheses-char #\[)
  107.     (#\] #. right-parentheses-char #\])
  108.     (#\: #\:)
  109.     (#\+ #\E #\B)
  110.     (#\- #\E #\B)
  111.     (#\* #\*)
  112.     (#\^)))
  113.     
  114. ;;; (FIND-NEXT-BREAK <list-of-fixnums>)
  115. ;;;   Tells how long it will be before the next allowable
  116. ;;;   text break in a list of chars.
  117.  
  118. #-cl
  119. (DEFUN FIND-NEXT-BREAK (L)
  120.        (DO ((I 0. (f1+ I))
  121.         (TEMP)
  122.         (L L (CDR L)))
  123.        ((NULL L) I)
  124.        (COND ((zl-MEMBER (CAR L) '(#\SPACE #\,)) (RETURN I))
  125.          ((AND (SETQ TEMP (ASSQ (CADR L) LINEAR-DISPLAY-BREAK-TABLE))
  126.                (NOT (MEMQ (CAR L) (CDR TEMP))))
  127.           (RETURN I)))))
  128.  
  129. ;;; (LINEAR-DISPLA1 <object> <indent-level>)
  130. ;;;  Displays <object> as best it can on this line.
  131. ;;;  If atom is too long to go on line, types # and a carriage return.
  132. ;;;  If end of line is found and an elegant break is seen 
  133. ;;;   (see FIND-NEXT-BREAK), it will type a carriage return and indent
  134. ;;;   <indent-level> spaces.
  135. #-cl
  136. (DEFUN LINEAR-DISPLA1 (X INDENT)
  137.        (LET ((CHARS (MSTRING X)))
  138.         (DO ((END-COLUMN  (f- (LINEL T) 3.))
  139.          (CHARS CHARS (CDR CHARS))
  140.          (I (CHARPOS T) (f1+ I))
  141.          (J (FIND-NEXT-BREAK CHARS) (f1- J)))
  142.         ((NULL CHARS) T)
  143.         (TYO (CAR CHARS))
  144.         (COND ((< J 1)
  145.                (SETQ J (FIND-NEXT-BREAK (CDR CHARS)))
  146.                (COND ((> (f+ I J) END-COLUMN)
  147.                   (TERPRI)
  148.                   (DO ((I 0. (f1+ I))) ((= I INDENT)) (TYO #\space))
  149.                   (SETQ I INDENT))))
  150.               ((= I END-COLUMN)
  151.                (PRINC '/#)
  152.                (TERPRI)
  153.                (SETQ I -1.))))))
  154.